package com.myjianzhu.zzt88.exercise.android.activities;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Base64;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

import com.myjianzhu.zzt88.carouse.CarouselActivity;
import com.myjianzhu.zzt88.exercise.R;
import com.myjianzhu.zzt88.exercise.android.databinding.DataBindingActivity;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.custom_widget)
    Button customWidget;
    @BindView(R.id.custom_view_group)
    Button customViewGroup;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.custom_widget)
    void clickCustomView() {
        CustomViewActivity.start(this);
    }

    @OnClick(R.id.custom_view_group)
    void clickCustomViewGroup() {

    }

    @OnClick(R.id.tag_view)
    void clickTagView() {
        MergeViewStubActivity.start(this);
    }

    @OnClick(R.id.data_binding)
    void clickDataBinding() {
        DataBindingActivity.start(this);
    }

    @OnClick(R.id.scroll_view)
    void clickScrollView() {
//        ScrollViewActivity.start(this);
    }

    @OnClick(R.id.carouse_view)
    void clickCarouse(){
        CarouselActivity.start(this);
    }

    @OnClick(R.id.get_key_hash)
    void getKeyHash() {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(

                    "com.esportsmatrix.dota2",

                    PackageManager.GET_SIGNATURES);

            for (Signature signature : info.signatures) {

                MessageDigest md = MessageDigest.getInstance("SHA");

                md.update(signature.toByteArray());

                String KeyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);

                Log.d("KeyHash:", "KeyHash:" + KeyHash);//两次获取的不一样  此处取第一个的值

                Toast.makeText(this, "FaceBook HashKey:" + KeyHash, Toast.LENGTH_SHORT).show();

            }

        } catch (PackageManager.NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }
    }

    @OnClick(R.id.demo2_activity)
    void clickDemo2() {
        DemoActivity_2.start(this);
    }

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, MainActivity.class);
        activity.startActivity(intent);
    }
}
